package com.originskyseed.platform.course.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.originskyseed.platform.core.aspect.annotation.RequiredParams;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.core.filter.helper.SingleSignOnTokenHelper;
import com.originskyseed.platform.course.i18n.CourseResponseMsg;
import com.originskyseed.platform.course.model.CourseStudyRecord;
import com.originskyseed.platform.course.model.Paper;
import com.originskyseed.platform.course.model.PaperRelateAnswer;
import com.originskyseed.platform.course.model.PaperRelateSubject;
import com.originskyseed.platform.course.model.PaperRelateSubjectOption;
import com.originskyseed.platform.course.model.PaperRelateUser;
import com.originskyseed.platform.course.model.TaskSelectPaperVO;
import com.originskyseed.platform.course.service.ICourseStudyRecordService;
import com.originskyseed.platform.course.service.IPaperRelateAnswerService;
import com.originskyseed.platform.course.service.IPaperRelateSubjectOptionService;
import com.originskyseed.platform.course.service.IPaperRelateSubjectService;
import com.originskyseed.platform.course.service.IPaperRelateUserService;
import com.originskyseed.platform.course.service.IPaperService;
import com.originskyseed.platform.course.vo.request.PaperRequestVO;
import com.originskyseed.platform.task.model.Task;
import com.originskyseed.platform.task.model.TaskRelateCourse;
import com.originskyseed.platform.task.service.ITaskRelateCourseService;
import com.originskyseed.platform.task.service.ITaskService;
import com.originskyseed.platform.user.model.UserInfo;

/**
 * 试卷信息Controller类（OSI_PAPER）
 *
 * @author Tangwanghui
 */
@Controller
@RequestMapping("/paper")
@BaseLocaleResource(localeFileName = "i18n_course")
public class PaperController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(PaperController.class);

	@DubboReference
	private IPaperService paperService;

	@DubboReference
	private IPaperRelateSubjectService paperRelateSubjectService;

	@DubboReference
	private IPaperRelateSubjectOptionService paperRelateSubjectOptionService;

	@DubboReference
	private IPaperRelateUserService paperRelateUserService;

	@DubboReference
	private ITaskService taskService;

	@DubboReference
	private IPaperRelateAnswerService paperRelateAnswerService;

	@DubboReference
	private ITaskRelateCourseService taskRelateCourseService;

	@DubboReference
	private ICourseStudyRecordService courseStudyRecordService;

	/**
	 * 分页查询
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/paperList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<Paper>> paperList(HttpServletRequest request) {
		BaseResponseBody<BasePage<Paper>> result = null;
		try {
			// 请求对象
			PaperRequestVO requestVO = this.getParameterBean(PaperRequestVO.class);
			requestVO.setIsDel(0);

			// 分页查询
			BasePage<Paper> page = new BasePage<Paper>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.paperService.selectListByPage(requestVO.toMap(), page);
			result = new BaseResponseBody<BasePage<Paper>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<Paper>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 任务发布试卷选择列表分页查询
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectPaperListByPage.json")
	@RequiredParams(names = { "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<TaskSelectPaperVO>> selectPaperListByPage(HttpServletRequest request) {
		BaseResponseBody<BasePage<TaskSelectPaperVO>> result = null;
		try {
			// 请求对象
			PaperRequestVO requestVO = this.getParameterBean(PaperRequestVO.class);

			// 分页查询
			BasePage<TaskSelectPaperVO> page = new BasePage<TaskSelectPaperVO>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.paperService.taskSelectListByPage(requestVO.toMap(), page);
			result = new BaseResponseBody<BasePage<TaskSelectPaperVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<TaskSelectPaperVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 保存信息
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/paperSave.json", method = RequestMethod.POST)
	public BaseResponseBody<Paper> paperSave(HttpServletRequest request) {
		BaseResponseBody<Paper> result = null;
		try {
			// 当前登陆人信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			// 请求对象
			Paper paper = this.getParameterBean(Paper.class);
			List<PaperRelateSubject> paperRelateSubjectList = this.getParameterList("paperRelateSubjectList", PaperRelateSubject.class);

			if (paperRelateSubjectList == null || paperRelateSubjectList.size() < 1) {
				return new BaseResponseBody<Paper>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.QUESTION_TYPE_ERROR.getMsg()), null);
			}

			if (StringUtils.isNotBlank(paper.getId())) {
				this.paperService.updatePaperAndPaperSubject(paper, paperRelateSubjectList);
			} else {
				// 设置课程id和创建人信息
				paper.setPaperNumber(createPaperNumber());
				paper.setCreatorId(userInfo.getId());
				paper.setCreator(userInfo.getName());
				paper.setState(1);
				paper.setIsTop(0);
				paper.setIsDel(0);
				Integer prority = this.paperService.selectPrority();
				if (prority == null) {
					paper.setPrority(0);
				} else {
					paper.setPrority(prority + 1);
				}
				this.paperService.insertPaperAndPaperSubject(paper, paperRelateSubjectList);
			}
			result = new BaseResponseBody<Paper>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_SUCCESS.getMsg()), paper);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<Paper>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 删除信息
	 *
	 * @param request
	 * @return
	 */
	/*
	 * @ResponseBody
	 * 
	 * @RequestMapping(value = "/paperDelete.json", method = RequestMethod.POST)
	 * 
	 * @RequiredParams(names = { "ids" }) public BaseResponseBody<Boolean> paperDelete(HttpServletRequest request) { BaseResponseBody<Boolean> result = null; try { // 请求参数 String[] ids = this.getParameterArray("ids", new String[] {});
	 * 
	 * this.paperService.deleteByPrimaryKeys(Arrays.asList(ids)); result = new BaseResponseBody<Boolean>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DELETE_SUCCESS.getMsg()), true); } catch (Exception e) { logger.error(e.getMessage(), e); result = new BaseResponseBody<Boolean>(false, CommonResponseCode.ERROR.getCode(),
	 * this.getLocaleMessage(this.getClass(), CourseResponseMsg.DELETE_ERROR.getMsg()), e.getMessage(), null); } return result; }
	 */

	/**
	 * 删除信息
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/paperDelete.json", method = RequestMethod.POST)
	@RequiredParams(names = { "ids" })
	public BaseResponseBody<Boolean> paperDelete(HttpServletRequest request) {
		BaseResponseBody<Boolean> result = null;
		try {
			// 请求参数
			String[] ids = this.getParameterArray("ids", new String[] {});
			Map<String, Object> map = new HashMap<>();
			map.put("list", Arrays.asList(ids));
			map.put("isDel", 1);

			this.paperService.updateIsDelByIds(map);
			result = new BaseResponseBody<Boolean>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DELETE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<Boolean>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DELETE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 批量修改状态
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/updatePaperState.json", method = RequestMethod.POST)
	@RequiredParams(names = { "ids", "state" })
	public BaseResponseBody<Boolean> updatePaperState(HttpServletRequest request) {
		BaseResponseBody<Boolean> result = null;
		try {
			// 请求参数
			String[] ids = this.getParameterArray("ids", new String[] {});
			Integer state = this.getParameterInteger("state", null);

			Map<String, Object> map = new HashMap<>();
			map.put("list", Arrays.asList(ids));
			map.put("state", state);

			this.paperService.updateStateByIds(map);
			result = new BaseResponseBody<Boolean>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<Boolean>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 通过考卷id查询详情
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectPaperById.json", method = RequestMethod.POST)
	@RequiredParams(names = { "id" })
	public BaseResponseBody selectPaperById(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求参数
			String id = this.getParameterString("id", null);
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);

			// 校验是否已经完成学习课程
			String taskId = this.getParameterString("taskId", null);
			if (taskId != null) {
				// 查询课程
				TaskRelateCourse taskRelateCourse = new TaskRelateCourse();
				taskRelateCourse.setTaskId(taskId);
				StringBuffer courseNames = new StringBuffer();// 课程名称
				List<TaskRelateCourse> taskRelateCourseList = this.taskRelateCourseService.selectList(taskRelateCourse);
				// 查询是否学习
				if (taskRelateCourseList != null && taskRelateCourseList.size() > 0) {
					for (TaskRelateCourse relateCourse : taskRelateCourseList) {
						CourseStudyRecord courseStudyRecord = this.courseStudyRecordService.selectIsStudy(relateCourse.getCourseId(), userInfo.getId(), 1, taskId);
						if (courseStudyRecord == null) {
							courseNames.append(relateCourse.getCourseName() + ",");
						}
					}
					// 为空就没学习
					if (StringUtils.isNotEmpty(courseNames)) {
						return new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SOURCE_NOT_STUDY_ERROR.getMsg()) + "：" + courseNames.substring(0, courseNames.length() - 1) + " 学习完成再参加考试~", null);
					}
				}
			}

			Paper paper = this.paperService.selectByPrimaryKey(id);

			PaperRelateSubject paperRelateSubject = new PaperRelateSubject();
			paperRelateSubject.setPaperId(id);
			List<PaperRelateSubject> paperRelateSubjectList = this.paperRelateSubjectService.selectList(paperRelateSubject);

			PaperRelateSubjectOption paperRelateSubjectOption = new PaperRelateSubjectOption();
			paperRelateSubjectOption.setPaperId(id);
			List<PaperRelateSubjectOption> paperRelateSubjectOptionList = this.paperRelateSubjectOptionService.selectList(paperRelateSubjectOption);
			paper.setPaperRelateSubjectList(paperRelateSubjectList);

			for (PaperRelateSubject paperRelateSubject1 : paperRelateSubjectList) {
				for (PaperRelateSubjectOption paperRelateSubjectOption1 : paperRelateSubjectOptionList) {
					if (paperRelateSubject1.getId().equals(paperRelateSubjectOption1.getStemId())) {
						if (paperRelateSubject1.getPaperRelateSubjectOptionList() == null) {
							paperRelateSubject1.setPaperRelateSubjectOptionList(new ArrayList<>());
						}
						paperRelateSubject1.getPaperRelateSubjectOptionList().add(paperRelateSubjectOption1);
					}
				}
			}

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_SUCCESS.getMsg()), paper);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询用户作答考卷信息
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectUserAnswerPaper.json", method = RequestMethod.POST)
	@RequiredParams(names = { "id", "userId" })
	public BaseResponseBody selectUserAnswerPaper(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求参数
			String paperId = this.getParameterString("paperId", null);
			String id = this.getParameterString("id", null);
			String userId = this.getParameterString("userId", null);
			String taskId = this.getParameterString("taskId", null);
			String answerNumber = this.getParameterString("answerNumber", null);
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			// 判断考卷是否以评，1.以评就可以展示答案，2如果未评，如果是任务创建人，需要展示答案。
			int isDisAnswer = 0;
			PaperRelateUser paperRelateUser = paperRelateUserService.selectByPrimaryKey(id);
			Task task = taskService.selectByPrimaryKey(taskId);
			if (task != null) {
				if (task.getCreatorId().equals(userInfo.getId())) {
					isDisAnswer = 1;
				} else {
					if (paperRelateUser != null) {
						if (paperRelateUser.getIsGrade() == 1) {
							isDisAnswer = 1;
						}
					}
				}
			}

			Paper paper = this.paperService.selectByPrimaryKey(paperId);
			PaperRelateSubject paperRelateSubject = new PaperRelateSubject();
			paperRelateSubject.setPaperId(paperId);
			List<PaperRelateSubject> paperRelateSubjectList = this.paperRelateSubjectService.selectList(paperRelateSubject);
			// System.out.println("===paperRelateSubjectList=="+paperRelateSubject);
			if (paperRelateSubjectList != null && paperRelateSubjectList.size() > 0) {
				for (PaperRelateSubject relateSubject : paperRelateSubjectList) {
					// 查询用户作答
					PaperRelateAnswer paperRelateAnswer = new PaperRelateAnswer();
					paperRelateAnswer.setCreatorId(userId);
					paperRelateAnswer.setTaskId(taskId);
					paperRelateAnswer.setPaperId(paperId);
					paperRelateAnswer.setStemId(relateSubject.getId());
					paperRelateAnswer.setAnswerNumber(answerNumber);
					int type = relateSubject.getType();

					PaperRelateAnswer answer = this.paperRelateAnswerService.selectPaperRelateAnswer(paperRelateAnswer);
					if (answer != null) {
						// System.out.println("===paperRelateSubjectList=answer="+answer);
						if (type == 3 || type == 4 || type == 6) { // 填空或简答题或其他
							if (answer.getContent() != null) {
								relateSubject.setUserAnswer(answer.getContent());// 客观题
							}
							relateSubject.setUserFileName(answer.getFileName());
							relateSubject.setUserFilePath(answer.getFilePath());
						}
					}

					PaperRelateSubjectOption paperRelateSubjectOption = new PaperRelateSubjectOption();
					paperRelateSubjectOption.setPaperId(paperId);
					paperRelateSubjectOption.setStemId(relateSubject.getId());
					List<PaperRelateSubjectOption> paperRelateSubjectOptionList = this.paperRelateSubjectOptionService.selectList(paperRelateSubjectOption);
					if (paperRelateSubjectOptionList != null && paperRelateSubjectOptionList.size() > 0) {
						String tempAnswer = "";
						for (int i = 0; i < paperRelateSubjectOptionList.size(); i++) {
							PaperRelateSubjectOption tempPaperRelateSubjectOption = paperRelateSubjectOptionList.get(i);
							if (tempPaperRelateSubjectOption.getIsAnswer() == 1) {
								tempAnswer = tempAnswer + tempPaperRelateSubjectOption.getContent() + ",";
							}
							tempPaperRelateSubjectOption.setIsAnswer(0);// 作答人的答案
							if (type == 1 || type == 2 || type == 5) {
								if (answer != null && answer.getOptionId() != null) {
									if (answer.getOptionId().indexOf(tempPaperRelateSubjectOption.getId()) > -1) {
										tempPaperRelateSubjectOption.setIsAnswer(1);
									}
								}
							}
						}
						if (tempAnswer.endsWith(",")) {
							tempAnswer = tempAnswer.substring(0, tempAnswer.length() - 1);
						}
						if (type == 1 || relateSubject.getType() == 2 || relateSubject.getType() == 5) {
							if (isDisAnswer == 1) {
								relateSubject.setAnswer(tempAnswer);// 参考答案
							}
						}
					}
					relateSubject.setPaperRelateSubjectOptionList(paperRelateSubjectOptionList);
				}
			}
			paper.setPaperRelateSubjectList(paperRelateSubjectList);
			paper.setAnswerTime(paperRelateUser == null ? null : paperRelateUser.getFinishTime());
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_SUCCESS.getMsg()), paper);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/*
	 * private String getPaperRelateAnswer(String taskId,String userId,String pageId,String stemId) throws Exception { PaperRelateAnswer paperRelateAnswer = new PaperRelateAnswer(); paperRelateAnswer.setCreatorId(userId); paperRelateAnswer.setTaskId(taskId); paperRelateAnswer.setPaperId(pageId); paperRelateAnswer.setStemId(stemId); PaperRelateAnswer answer =
	 * this.paperRelateAnswerService.selectPaperRelateAnswer(paperRelateAnswer); String optionId=answer==null?"":answer.getOptionId(); return optionId; }
	 */

	/**
	 * 修改置顶信息
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/updateIsTop.json", method = RequestMethod.POST)
	@RequiredParams(names = { "id" })
	public BaseResponseBody updateIsTop(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求参数
			String id = this.getParameterString("id", null);

			Paper paper = new Paper();
			paper.setId(id);
			paper.setIsTop(1);
			paper.setUpdateTime(new Date());
			this.paperService.updateIsTop(paper);
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 升序降序
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/updateUpOrDown.json", method = RequestMethod.POST)
	@RequiredParams(names = { "id", "upOrDown", "prority" })
	public BaseResponseBody updateUpAndDown(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求参数
			String id = this.getParameterString("id", null);
			Integer upOrDown = this.getParameterInteger("upOrDown", null);

			// 查询优先级
			Paper query = this.paperService.selectByPrimaryKey(id);
			Integer prority = query.getPrority();
			Map<String, Object> map = new HashMap<>();
			map.put("type", upOrDown);
			map.put("prority", prority);
			// 将另外一个升序或降序
			Paper paper = this.paperService.selectPaperByPrority(map);

			Paper updatePaper = new Paper();
			updatePaper.setId(id);
			if (paper != null) {
				updatePaper.setPrority(paper.getPrority());
				paper.setPrority(prority);
			} else {
				// 等于0是升序 1是降序
				if (upOrDown == 0) {
					updatePaper.setPrority(prority + 1);
				} else {
					updatePaper.setPrority(prority - 1);
				}
			}
			if (paper != null) {
				this.paperService.updatePrority(paper, updatePaper);
			} else {
				this.paperService.updateByPrimaryKeySelective(updatePaper);
			}

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 获取考卷id
	 * 
	 * @return
	 * @throws Exception
	 */
	private String createPaperNumber() throws Exception {
		// 获得当前时间戳
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		String dateString = formatter.format(currentTime);
		// 生成随机数（随机数范围：1000到10000）
		int num = (int) (Math.random() * (10000 - 1000) + 1000);
		dateString += num;

		// 判断考卷编号是否已存在
		String paperNumber = this.paperService.selectPaperNumber(dateString);
		if (StringUtils.isNotEmpty(paperNumber)) {
			return createPaperNumber();
		} else {
			return dateString;
		}
	}

}
